// components/multiple_selection/multiple_selection.js
Component({
  /**
   * 组件的属性列表
   */
  /**
   * 组件的属性列表
   */
  properties: {
    //标题文字
    multipleContent: {
      type: String,
      value: ''
    },
    multiple_list: {
      type: Array,
      value: []
    },
    top: {
      type: String,
      value: ""
    },
    height: {
      type: String,
      value: ""
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    is_clicked: 'choosed',
    // 弹窗显示控制
    isShow: false,
    list: '',
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {

    },

  },
  lifetimes: {
    ready() {
      let that = this;
      let multiple_list = this.triggerEvent('multiple_list', this.properties.multiple_list);
      setTimeout(function () {
        that.setData({
          list: that.properties.multiple_list
        }, function () {
          // console.log('multiple_list',that.properties.multiple_list);
        })
      }, 200)
    },
  },
  /**
   * 组件的方法列表
   */

  methods: {
    //选中
    choose_item: function (e) {
      var temp = e.currentTarget.dataset.mkh;
      var list_new = this.data.list;
      var check_item = {};
      check_item = list_new[temp];
      check_item.type = check_item.type == "choosed" ? "" : "choosed";
      list_new[temp] = check_item;
      // console.log(list_new);
      this.setData({
        list: list_new,
      })
      // this.triggerEvent('showMultiple',{isShow:this.data.isShow})
    },
    //隐藏弹框
    hideMultiple: function () {
      // console.log('隐藏弹框');
      this.setData({
        isShow: false,
      })
      // this.triggerEvent('showMultiple',{isShow:this.data.isShow})
    },
    // 重置数据
    newMultiple: function () {
      let list = this.data.list;
      list.map(item => {
        item.type = ''
      })
      this.setData({
        isShow: false,
        list: list
      });
      this.triggerEvent('_multipleConfirm', {
        userCertificateList: []
      })
    },
   //展示弹框
    showMultiple: function (e) {
      // console.log('展示多选', this);
      if (this.id == "multiple1") {

      }
      if (!this.data.list.length) {
        this.setData({
          isShow: true,
          list: this.data.multiple_list
        })
      } else {
        this.setData({
          isShow: true,
        })
      }
      this.triggerEvent('showMultiple', {
        isShow: this.data.isShow
      })
    },
    /*
     * 内部私有方法建议以下划线开头
     * triggerEvent 用于触发事件
     */
    _multipleCancel() {
      //触发取消回调
      var return_list = [];
      for (var i = 0; i < this.data.list.length; i++) {
        if (this.data.list[i].type == "choosed") {
          return_list.push(this.data.list[i]);
        } else {
          continue;
        }
      }
      this.triggerEvent("multipleCancel", return_list)
    },
    _multipleConfirm() {
      //触发成功回调
      var return_list = [];
      for (var i = 0; i < this.data.list.length; i++) {
        if (this.data.list[i].type == "choosed") {
          return_list.push(this.data.list[i]);
        } else {
          continue;
        }
      }
      this.triggerEvent("multipleConfirm", return_list);
    }

  }
})